<?php
/**
 * @auther:周卫星
 * @className:AdminLoginMiddleware.php
 * @projectName:train
 * @classDesc:
 * @date:2019/10/24
 * @time:14:08
 */

namespace App\Http\Middleware;


use Illuminate\Http\Request;

class AdminLoginMiddleware
{
    /**
     * 验证后台是否登录
     * @param Request $request
     * @param \Closure $next
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     */
    public function handle(Request $request, \Closure $next)
    {
        $admin = $request -> session() -> has('admin');
        if (!$admin){
            $request -> session() -> flash('illegal', '请先登录');
            return redirect(url('/login'));
        }
        return $next($request);
    }
}
